package com.heima.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.heima.mapper.TbNodeMapper;
import com.heima.pojo.TbNode;
import com.heima.pojo.vo.NodeVo;
import com.heima.pojo.vo.PageResponse;
import com.heima.pojo.vo.VendingMachineVo;
import com.heima.service.ITbNodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 点位表 服务实现类
 * </p>
 *
 * @author nan
 * @since 2024-06-09
 */
@Service
public class TbNodeServiceImpl extends ServiceImpl<TbNodeMapper, TbNode> implements ITbNodeService {

    @Autowired
    private TbNodeMapper nodeMapper;

    /**
     * 查看区域详情
     *
     * @param pageIndex
     * @param pageSize
     * @param regionId
     * @return
     */
    @Override
    public PageResponse<NodeVo> getByPage(Integer pageIndex, Integer pageSize, String regionId, String name) {

        Page<TbNode> page = new Page<>(pageIndex, pageSize);

        Page<NodeVo> nodeVoPage = nodeMapper.getByPage(page, regionId, name);
        PageResponse<NodeVo> pageResponse = new PageResponse<>();
        pageResponse.setPageIndex(nodeVoPage.getCurrent());
        pageResponse.setPageSize(nodeVoPage.getSize());
        pageResponse.setTotalPage(nodeVoPage.getPages());
        pageResponse.setTotalCount(nodeVoPage.getTotal());
        pageResponse.setCurrentPageRecords(List.copyOf(nodeVoPage.getRecords()));
        return pageResponse;
    }

    /**
     * 获取点位详情
     *
     * @param nodeId
     * @return
     */
    @Override
    public List<VendingMachineVo> getByNodeId(String nodeId) {
        return nodeMapper.getByNodeId(nodeId);
    }

}
